package com.taxshare.operation.controller;

import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.response.beans.Response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.taxshare.operation.service.CodeDetailService;
import com.taxshare.operation.service.CodeService;
import com.taxshare.operation.view.dto.CodeInfoDTO;
import com.taxshare.operation.view.vo.CodeDetailVO;
import com.taxshare.operation.view.vo.CodeInfoVO;

/**
    * @ClassName: CommonCodeController
    * @Description: (码表)
    * @author liupp
    * @date 2021年1月22日
    *
 */
@RestController
@RequestMapping(value = "/common/code")
@Api(tags = "通用码表")
public class CodeController{

	@Autowired
    private CodeService commonCodeService;
    @Autowired
    private CodeDetailService codeDetailService;

    @RequestMapping(method = RequestMethod.POST, value = "/info/queryList")
    @ApiOperation(notes = "通用码表", value = "通用码下拉菜单")
    public Response<List<CodeInfoVO>> queryList(@RequestBody CodeInfoDTO commonCodeInfoDTO) {
        return commonCodeService.queryList(commonCodeInfoDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/queryPageList")
    @ApiOperation(notes = "通用码表【分页】", value = "通用码表【分页】")
    public Response<IPage<CodeInfoVO>> queryPageList(@RequestBody PageRequest<CodeInfoDTO> query) {
        return commonCodeService.queryPageList(query);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/add")
    @ApiOperation(notes = "通用码表", value = "新增")
    public Response add(@RequestBody CodeInfoDTO commonCodeInfoDTO) {
        return commonCodeService.add(commonCodeInfoDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/edit")
    @ApiOperation(notes = "通用码表", value = "编辑")
    public Response edit(@RequestBody CodeInfoDTO commonCodeInfoDTO) {
        return commonCodeService.edit(commonCodeInfoDTO);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/info/delete")
    @ApiOperation(notes = "通用码表", value = "删除")
    public Response delete(@ApiParam(value = "唯一标识", required = true)@RequestBody String uuid) {
        return commonCodeService.delete(uuid);
    }

    /**
     * 明细,查询
     */
    @RequestMapping(method = RequestMethod.POST, value = "/detail/queryPageList")
    @ApiOperation(value = "通用码明细,查询", notes = "明细,查询,分页")
    public Response getDetailInfoList(@RequestBody PageRequest<CodeDetailVO> query) {
        return codeDetailService.queryPageList(query);
    }

    /**
     * 明细,新增
     */
    @RequestMapping(method = RequestMethod.POST, value = "/detail/add")
    @ApiOperation(value = "通用码明细,新增", notes = "明细,新增")
    public Response addDetailInfo(@RequestBody CodeDetailVO codeDetailVO) {
        return codeDetailService.addDetailInfo(codeDetailVO);
    }

    /**
     * 明细,编辑
     */
    @RequestMapping(method = RequestMethod.POST, value = "/detail/update")
    @ApiOperation(value = "通用码明细,编辑", notes = "明细,编辑")
    public Response updateDetailInfo(@RequestBody CodeDetailVO codeDetailVO) {
        return codeDetailService.updateDetailInfo(codeDetailVO);
    }

    /**
     * 明细,删除
     */
    @RequestMapping(method = RequestMethod.POST, value = "/detail/delete")
    @ApiOperation(value = "通用码明细,删除", notes = "明细,删除")
    public Response deleteDetailInfo(@RequestBody String uuid) {
        return codeDetailService.deleteDetailInfo(uuid);
    }
    
    @RequestMapping(method = RequestMethod.POST, value = "/detail/update/expire/status")
    @ApiOperation(value = "通用码明细,修改状态", notes = "明细,修改状态")
    public Response updateExpireStatus(@RequestBody CodeDetailVO codeDetailVO) {
        return codeDetailService.updateExpireStatus(codeDetailVO);
    }
    
    @RequestMapping(method = RequestMethod.POST, value = "/detail/queryList")
    @ApiOperation(notes = "通用码表", value = "通用码明细下拉")
    public Response<List<CodeDetailVO>> queryDetailList(@RequestParam String currentCollectionCode) {
        return codeDetailService.queryDetailList(currentCollectionCode);
    }
}
